﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using System.Diagnostics;

namespace MyEngineExercise.我的扩展.窗体
{
    public partial class FeatureLayerInfoForm : Form
    {
        private IFeatureLayer _featureLayer = null;
        private IWorkspace _workspace = null;

        public FeatureLayerInfoForm()
        {
            InitializeComponent();
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        public FeatureLayerInfoForm(IFeatureLayer featureLayer):this()
        {
            _featureLayer = featureLayer;

            IFeatureClass featureClass = _featureLayer.FeatureClass;
            IFeatureSelection featureSelection = (IFeatureSelection)_featureLayer;

            String newline = Environment.NewLine;

            this.Text = "\"" + _featureLayer.Name + "\"图层的图层属性";

            this.richTextBox1.AppendText("数据来源：" + newline + featureClass.GetFullPath() + newline + newline);

            this.richTextBox1.AppendText("图层类型：" + featureClass.ShapeType.ToString() + newline + newline);

            this.richTextBox1.AppendText("记录总数：" + featureClass.FeatureCount(null).ToString() + "条，其中" + featureSelection.SelectionSet.Count.ToString() + "条选中");

            button1.Enabled = featureClass.IsShapeFile();

            _workspace = MyAeMethods.Instance.NewWorkspace(featureClass);
        }


        /// <summary>
        /// 打开文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if(System.IO.Directory.Exists(_workspace.PathName))
            {
                //Process process=new Process();
                //process.StartInfo.FileName=_workspace.PathName;
                //process.Start();
                MyMethods.startProcess(_workspace.PathName);
            }
        }

        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
